package com.cnzha.mr.flowsum;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: zhaoxin
 * @email: zdkk@foxmail.com
 * @Date: 3/31/2020 3:48 PM
 */
public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1	13736230513	192.196.100.1	www.atguigu.com	2481	24681	200
        String[] split = value.toString().split("\t");
        String mobile = split[1];
        String upFlow = split[split.length - 3];
        String downFlow = split[split.length - 2];
        k.set(mobile);
        v.set(Long.valueOf(upFlow), Long.valueOf(downFlow));
        context.write(k, v);
    }
}
